﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SubForum.ObjectModel.Posts;

namespace SubForum.ObjectModel.Tags
{
    public class TagList<T> : List<T> where T : Tag , new()
    {
        public TagList()
        {
        }

        public TagList(string tagsList, Post post)
            : this()
        {
            string[] tags = tagsList.Split(',');

            foreach (string tag in tags)
            {
                this.Add(new T() { TagName = tag.Trim(), Post = post });
            }
        }

        public override string ToString()
        {
            StringBuilder tagsList = new StringBuilder();

            foreach (Tag tag in this)
            {
                tagsList.Append(tag.TagName + ", ");
            }
           
            return tagsList.ToString();
        }
    }
}
